package com.yssoft.utils;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * app取出用户信息
 */
public class AppUserHelper {
	/**
	 * 获取当前登录用户信息.
	 */
	public static Map<String,Object> getCurrentUser(HttpServletRequest request) {
        Map<String,Object> personnel = (Map<String,Object>) request.getSession().getAttribute("appUser");
	    return personnel;
	}

	/**
	 * 取出session中的当前用户Id.
	 */
	public static Integer getCurrentUserId(HttpServletRequest request) {
        Map<String,Object> personnel = (Map<String,Object>) request.getSession().getAttribute("appUser");
        if(personnel.get("id")!=null && personnel.get("id").toString().length()>0){
            return Integer.parseInt(personnel.get("id").toString());
        }else{
            return null;
        }
	}
	/**
	 * 取出session中的当前用户名称.
	 */
	public static String getCurrentUserName(HttpServletRequest request) {
        Map<String,Object> personnel = (Map<String,Object>) request.getSession().getAttribute("appUser");
		return personnel.get("name")==null?null:personnel.get("name").toString();
	}

	/**
	 * 取出session中的当前用户企业Id.
	 */
	public static Integer getCurrentCompanyId(HttpServletRequest request) {
        Map<String,Object> personnel = (Map<String,Object>) request.getSession().getAttribute("appUser");
        if(personnel.get("tEId")!=null && personnel.get("tEId").toString().length()>0){
        	//return 29;
           return Integer.parseInt(personnel.get("tEId").toString());
        }else{
            return null;
        }
	}
	/**
	 * 取出session中的当前用户部门Id.
	 */
	public static Integer getCurrentDeptId(HttpServletRequest request) {
        Map<String,Object> personnel = (Map<String,Object>) request.getSession().getAttribute("appUser");
        if(personnel.get("tDId")!=null && personnel.get("tDId").toString().length()>0){
            return Integer.parseInt(personnel.get("tDId").toString());
        }else{
            return null;
        }
	}
	
	/**
	 * 取出session中的当前用户企业名称.
	 */
	public static String getCurrentCompanyName(HttpServletRequest request) {
        Map<String,Object> personnel = (Map<String,Object>) request.getSession().getAttribute("appUser");
		return personnel.get("companyName")==null?null:personnel.get("companyName").toString();
	}
	/**
	 * 取出session中的当前用户部门名称.
	 */
	public static String getCurrentDeptName(HttpServletRequest request) {
        Map<String,Object> personnel = (Map<String,Object>) request.getSession().getAttribute("appUser");
		return personnel.get("deptName")==null?null:personnel.get("deptName").toString();
	}
	
	
	
}
